package tests;
import util.*;
import meal.*;
//import java.sql.*;

public class DataBaseTest {
	public static void main(String[] args) {
		System.out.println("test start");
		DataBase.init();
		Meal meal = new Meal(
				"Brown Rice",
				new Ingredient[] {
					new Ingredient("Rice",5,"cups"),
					new Ingredient("Eggs",3),
			 		new Ingredient("Salt"),
			 		new Ingredient("Onions",2)
				},
				new Direction[] {
					new Direction("Get small pan"),
			 		new Direction("Put rice in small pan"),
			 		new Direction("Put 5 cups of water into pan"),
			 		new Direction("Etc."),
			 		new Direction("Win!")
				},
				0.5,
				123456
		);
		Meal meal2 = new Meal(
				"Brown Rice2",
				new Ingredient[] {
					new Ingredient("Rice",5,"cups"),
					new Ingredient("Eggs",3),
			 		new Ingredient("Salt"),
			 		new Ingredient("Onions",2)
				},
				new Direction[] {
					new Direction("Get small pan"),
			 		new Direction("Put rice in small pan"),
			 		new Direction("Put 5 cups of water into pan"),
			 		new Direction("Etc."),
			 		new Direction("Win!")
				},
				0.9,
				123456
		);
		Meal meal3 = null;
		Meal meal4 = new Meal(
				"Brown Rice",
				new Ingredient[] {
					new Ingredient("Rice",5,"cups"),
					new Ingredient("Eggs",3),
			 		new Ingredient("Salt"),
			 		new Ingredient("Onions",2)
				},
				new Direction[] {
					new Direction("Get small pan"),
			 		new Direction("Put rice in small pan"),
			 		new Direction("Put 5 cups of water into pan"),
			 		new Direction("Etc."),
			 		new Direction("Win!")
				},
				0.7,
				123456
		);

		String[] testNames;
		try {
			DataBase.saveMeal(meal);
			DataBase.saveMeal(meal2);
			DataBase.saveMeal(meal4);
			DataBase.deleteMeal(meal3);
			testNames = DataBase.getMealName();
			if (testNames == null) {
				System.out.println("test failed");
				return;
			}
			System.out.println(testNames[0]);
			Meal testMeal = DataBase.getMeal(testNames[0]);
			Meal testMeal2 = DataBase.getMeal(testNames[1]);
			System.out.println("meal rating : " + testMeal.getRating());
			System.out.println("meal rating2 : " + testMeal2.getRating());
			
			System.out.println("meal ingredient[0] : " + (testMeal.getIngredients())[0].getName()); 

			DataBase.deleteMeal(meal);
			DataBase.deleteMeal(meal2);
			testMeal = DataBase.getMeal(meal2.getName());
		} catch(Exception e) {
			e.printStackTrace();
		}

//		System.out.println(meal);

//		meal = new Meal();
//		meal.setIngredients(new Ingredient[]{ new Ingredient("Rice",3) });

//		System.out.println(meal);
	}
}
